package com.daidai.transform;

import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

import java.util.Arrays;

public class UnionAndConnect {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<String> source1 = env.fromCollection(Arrays.asList("hello", "how", "are", "you"));
        DataStreamSource<String> source2 = env.fromCollection(Arrays.asList("java", "python", "scala"));
        DataStreamSource<Integer> source3 = env.fromCollection(Arrays.asList(1, 2, 3, 4));

        source1.union(source2).print("union--string_string");

        ConnectedStreams<String, Integer> connect = source1.connect(source3);
        connect.map(new CoMapFunction<String, Integer, String>() {
            @Override
            public String map1(String value) throws Exception {
                return value;
            }

            @Override
            public String map2(Integer value) throws Exception {
                return value+"";
            }
        }).print("connect--string_int");


        env.execute();

    }
}
